<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>督查任务</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/duTask.css">
</head>

<body>
    <div class="top-navigation">
        <img class="arrow" onclick="backIndex()" src="img/arrow.png" alt="图片加载中">
        <h3>督查任务</h3>
        <img class="search" src="img/search.png" alt="图片加载中" style="opacity: 0;">
    </div>

    <!-- 底部tab页 -->
    <ul class="tab-content">
        <li class="active">全部</li>
        <li>未完成</li>
        <li>已完成</li>
        <li>已考核</li>
        <!-- <li>失效</li> -->
    </ul>

    <ul class="tab2-content">
        <li class="active">全部</li>
        <li>第一轮督查</li>
        <li>第二轮督查</li>
        <li>第三轮督查</li>
    </ul>

    <!--容器-->
    <div class="containers">
        <!-- <div class="report-item">
            <h3>1</h3>
            <div>
                <div class="first-row">
                    <p class="title hidden-font">嵩口人民法庭迁建18.1"…</p>
                    <p class="name">第二轮</p>
                </div>
                <div class="second-row">
                    <p class="depart hidden-font">县委督查室 - 林淮</p>
                    <p class="date">计划结束：2019.08.24</p>
                </div>
            </div>
        </div> -->
    </div>
    <div id="load" style="display: none;">
        <div class="load-tip">
            <p></p>
            <h3>点击加载更多</h3>
            <p></p>
        </div>
    </div>

    <script src="js/flexible.js"></script>
    <script src="js/jquery-3.2.1.js"></script>
    <!-- VConsole手机调试 -->
    <!-- <script src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script> -->
    <script>
        // var vConsole = new VConsole();

        // 切换tab
        $(".tab-content").on("click", "li", function () {
            $("#load").css("display", "none");
            $(this).addClass("active").siblings().removeClass("active");
            var val = $(this).text();
            page = 1;
            num = 0;
            $(".containers").empty();
            if (val === "全部") {
                taskResult1 = "";
            } else if (val === "未完成") {
                taskResult1 = 0;
            } else if (val === "已完成") {
                taskResult1 = 1;
            } else if (val === "已考核") {
                taskResult1 = 3;
            }
            console.log(taskResult1);
            loadContent();
        });

        // 切换tab2栏
        $(".tab2-content").on("click", "li", function () {
            $("#load").css("display", "none");
            $(this).addClass("active").siblings().removeClass("active");
            var val = $(this).text();
            page = 1;
            num = 0;
            $(".containers").empty();
            if (val === "全部") {
                tasktimes1 = "";
            } else if (val === "第一轮督查") {
                tasktimes1 = 1;
            } else if (val === "第二轮督查") {
                tasktimes1 = 2;
            } else if (val === "第三轮督查") {
                tasktimes1 = 3;
            }
            console.log(tasktimes1);
            loadContent();
        });
    </script>
    <!-- 请求数据 -->
    <script>
        var page = 1;
        var num = 0;
        var tasktimes1 = ""; //轮次  1 2 3 
        var taskResult1 = ""; //完成1    未完0  以考核3
        var branchType = ""; //用户类型
        // 获取用户电话号码
        var userPhone = window.AndroidWebView.getUserId();

        function loadContent(page) {
            $.ajax({
                // url: "https://www.fzzhengxinyun.com/zhApp/supervisionTask/lists",
                url: "http://120.78.158.120:8099/zhApp/supervisionTask/lists",
                type: "POST",
                dataType: "json", //返回数据形式为json
                contentType: 'application/json;charset=UTF-8',
                data: JSON.stringify({
                    "userPhone": userPhone,
                    "tasktimes": tasktimes1,
                    "taskResult": taskResult1,
                    "paging": {
                        "currentPage": page
                    }
                }),
                success: function (res) {
                    console.log(res);
                    if (res.code === "200" && res.data !== undefined) {
                        $("#load").css("display", "block");
                        var item = res.data;
                        branchType = res.userAuth.branchType;
                        console.log(branchType);

                        if (item.length < 10) {
                            $("#load").css("display", "none");
                        }

                        var html = "";
                        for (var i = 0; i < item.length; i++) {
                            num++
                            html = '\
                           <div class="report-item" data-id="' + item[i].sysId + '">\
                               <h3>' + num + '</h3>\
                               <div>\
                                   <div class="first-row">\
                                       <p class="title hidden-font">' + item[i].nodeName + '</p>\
                                       <p class="name">第' + item[i].tasktimes + '轮</p>\
                                   </div>\
                                   <div class="second-row">\
                                       <p class="depart hidden-font">' + item[i].groupType + ' - ' + item[i]
                                .inspectors + '</p>\
                                       <p class="date">计划结束：' + item[i].planEndDate + '</p>\
                                   </div>\
                               </div>\
                           </div>\
                            ';
                            $(".containers").append(html);
                        }

                    }
                    if (res.data !== undefined) {

                        $(".load-tip h3").html("点击加载更多");
                    } else {
                        $(".load-tip h3").html("数据已加载完毕");
                    }
                }
            });
        }

        $(function () {
            loadContent(page);

            $(".load-tip").click(function () {
                page++
                console.log("page:" + page);
                $(".load-tip h3").html("数据正在加载中");
                loadContent(page);
            });

            // 督查任务跳转催办记录
            $(".containers").on("click", ".report-item", function () {
                var sysId = $(this).data("id");
                if (branchType === "0" || branchType === "1") {
                    window.location.href = "./feedback.html?sysId=" + sysId + "&isHide=false";
                } else if (branchType === "4") {
                    window.location.href = "./cuiban.html?sysId=" + sysId;
                } else {
                    window.location.href = "./feedback.html?sysId=" + sysId + "&isHide=true";
                }

            });
        });

        // 返回安卓首页
        function backIndex() {
            window.AndroidWebView.showInfoFromJs()
        }
    </script>
</body>

</html>